﻿Imports System.Windows.Controls

Namespace Views


    Public Class ViewGridDefinitionEdtior

        Sub New()

            ' Cet appel est requis par le concepteur.
            InitializeComponent()

            ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().

        End Sub

        Sub New(ByVal rowdef As RowDefinition)

            ' Cet appel est requis par le concepteur.
            InitializeComponent()

            ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
            Me.DataContext = New RowDefinitionFacade() With {.brother = rowdef}
        End Sub

        Sub New(ByVal toprowdef As RowDefinition, ByVal bottomrowdef As RowDefinition)

            ' Cet appel est requis par le concepteur.
            InitializeComponent()

            ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
            Me.DataContext = New RowDefinitionFacade() With { _
                .brother = toprowdef, _
                .brothers = New RowDefinition() {toprowdef, bottomrowdef}}
        End Sub

        Sub New(ByVal coldef As ColumnDefinition)

            ' Cet appel est requis par le concepteur.
            InitializeComponent()

            ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().

            Me.DataContext = New ColumnDefinitionFacade() With {.brother = coldef}

        End Sub
        'Sub New(ByVal coldef As ColumnDefinition)

        '    ' Cet appel est requis par le concepteur.
        '    InitializeComponent()

        '    ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().

        '    Me.DataContext = New ColumnDefinitionFacade() With {.brother = coldef}

        'End Sub

        Private Class RowDefinitionFacade
            Implements ComponentModel.INotifyPropertyChanged

            Friend brother As RowDefinition

            Friend brothers() As RowDefinition

            Public Property Current As Boolean
                Get
                    Return brothers(0) Is brother
                End Get
                Set(ByVal value As Boolean)
                    If value Then
                        brother = brothers(0)
                    Else
                        brother = brothers(1)
                    End If
                    RaiseEvent PropertyChanged(Me, New ComponentModel.PropertyChangedEventArgs("Size"))
                    RaiseEvent PropertyChanged(Me, New ComponentModel.PropertyChangedEventArgs("SizeType"))
                End Set
            End Property


            Property Size As Double
                Get
                    Return brother.Height.Value
                End Get
                Set(ByVal value As Double)
                    If brother.Height.IsAuto Then Return
                    If brother.Height.IsStar Then
                        brother.Height = New Windows.GridLength(value / 100.0, Windows.GridUnitType.Star)
                        Return
                    End If
                    If brother.Height.IsAbsolute Then
                        brother.Height = New Windows.GridLength(value)
                        Return
                    End If
                End Set
            End Property

            Property MinSize As Double
                Get
                    Return brother.MinHeight
                End Get
                Set(ByVal value As Double)

                End Set
            End Property

            Property MaxSize As Double
                Get
                    Return brother.MaxHeight
                End Get
                Set(ByVal value As Double)

                End Set
            End Property

            Property SizeType As Integer
                Get
                    If brother.Height.IsAuto Then Return 0
                    If brother.Height.IsStar Then Return 2
                    If brother.Height.IsAbsolute Then Return 1
                    Return -1
                End Get
                Set(ByVal value As Integer)
                    If value = 0 Then
                        brother.Height = Windows.GridLength.Auto
                        Return
                    End If

                    If brother.Height.IsAbsolute And value <> 1 Then
                        If value = 2 Then
                            brother.Height = New Windows.GridLength(1, Windows.GridUnitType.Star)
                            Return
                        End If
                    End If

                    If brother.Height.IsStar And value <> 2 Then
                        If value = 1 Then
                            brother.Height = New Windows.GridLength(brother.ActualHeight)
                            Return
                        End If
                    End If

                    If brother.Height.IsAuto Then
                        If value = 1 Then
                            brother.Height = New Windows.GridLength(brother.ActualHeight)
                            Return
                        End If
                        If value = 2 Then
                            brother.Height = New Windows.GridLength(1, Windows.GridUnitType.Star)
                            Return
                        End If
                    End If
                End Set
            End Property

            Property Blocked As Boolean
                Get
                    Return True
                End Get
                Set(ByVal value As Boolean)

                End Set
            End Property

            Property Active As Boolean
                Get
                    Return True
                End Get
                Set(ByVal value As Boolean)

                End Set
            End Property

            Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
        End Class

        Private Class ColumnDefinitionFacade

            Friend brother As ColumnDefinition

            Public Property SelectedBrother As Integer


            Property Size As Double
                Get
                    Return brother.Width.Value
                End Get
                Set(ByVal value As Double)
                    If brother.Width.IsAuto Then Return
                    If brother.Width.IsStar Then
                        brother.Width = New Windows.GridLength(value / 100.0, Windows.GridUnitType.Star)
                        Return
                    End If
                    If brother.Width.IsAbsolute Then
                        brother.Width = New Windows.GridLength(value)
                        Return
                    End If
                End Set
            End Property

            Property MinSize As Double
                Get
                    Return brother.MinWidth
                End Get
                Set(ByVal value As Double)

                End Set
            End Property


            Property MaxSize As Double
                Get
                    Return brother.MaxWidth
                End Get
                Set(ByVal value As Double)

                End Set
            End Property


            Property SizeType As Integer
                Get
                    If brother.Width.IsAuto Then Return 0
                    If brother.Width.IsStar Then Return 2
                    If brother.Width.IsAbsolute Then Return 1
                    Return -1
                End Get
                Set(ByVal value As Integer)
                    If value = 0 Then
                        brother.Width = Windows.GridLength.Auto
                        Return
                    End If

                    If brother.Width.IsAbsolute And value <> 1 Then
                        If value = 2 Then
                            brother.Width = New Windows.GridLength(1, Windows.GridUnitType.Star)
                            Return
                        End If
                    End If

                    If brother.Width.IsStar And value <> 2 Then
                        If value = 1 Then
                            brother.Width = New Windows.GridLength(brother.ActualWidth)
                            Return
                        End If
                    End If

                    If brother.Width.IsAuto Then
                        If value = 1 Then
                            brother.Width = New Windows.GridLength(brother.ActualWidth)
                            Return
                        End If
                        If value = 2 Then
                            brother.Width = New Windows.GridLength(1, Windows.GridUnitType.Star)
                            Return
                        End If
                    End If
                End Set
            End Property

            Property Blocked As Boolean
                Get
                    Return True
                End Get
                Set(ByVal value As Boolean)

                End Set
            End Property

            Property Active As Boolean
                Get
                    Return True
                End Get
                Set(ByVal value As Boolean)

                End Set
            End Property
        End Class
    End Class
End Namespace